<!DOCTYPE html>
<html id="docs" lang="en" class="">
	<head>
	<meta charset="utf-8">
<title>Kubernetes 101 - Kubernetes</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/png" href="../../../images/favicon.png">
<link rel="stylesheet" type="text/css" href="../../../css/base_fonts.css">
<link rel="stylesheet" type="text/css" href="../../../css/styles.css">
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">
<link rel="stylesheet" type="text/css" href="../../../css/callouts.css">
<link rel="stylesheet" type="text/css" href="../../../css/custom-jekyll/tags.css">




<meta name="description" content="Kubernetes 101" />
<meta property="og:description" content="Kubernetes 101" />

<meta property="og:url" content="https://kubernetes.io/docs/tutorials/k8s101/" />
<meta property="og:title" content="Kubernetes 101 - Kubernetes" />

<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<script src="../../../js/script.js"></script>
<script src="../../../js/custom-jekyll/tags.js"></script>


	</head>
	<body>
		<div id="cellophane" onclick="kub.toggleMenu()"></div>

<header>
    <a href="../../../index.html" class="logo"></a>

    <div class="nav-buttons" data-auto-burger="primary">
        <ul class="global-nav">
            
            
            <li><a href="../../home.1">Documentation</a></li>
            
            <li><a href="../../../blog/index.html">Blog</a></li>
            
            <li><a href="../../../partners/index.html">Partners</a></li>
            
            <li><a href="../../../community/index.html">Community</a></li>
            
            <li><a href="../../../case-studies/index.html">Case Studies</a></li>
            
            
             <li>
                <a href="../../user-guide/walkthrough/index.html#">
                    English <span class="ui-icon ui-icon-carat-1-s"></span>
                </a>
                <ul>
                
                    <li><a href="../../../zh/index.html">中文 Chinese</a></li>
                
                    <li><a href="../../../ko/index.html">한국어 Korean</a></li>
                
                </ul>
            </li>
         
            <li>
                <a href="../../user-guide/walkthrough/index.html#">
                    v1.11 <span class="ui-icon ui-icon-carat-1-s"></span>
                </a>
                <ul>
                
                    <li><a href="https://kubernetes.io">v1.12</a></li>
                
                    <li><a href="../../../index.html">v1.11</a></li>
                
                    <li><a href="https://v1-10.docs.kubernetes.io">v1.10</a></li>
                
                    <li><a href="https://v1-9.docs.kubernetes.io">v1.9</a></li>
                
                </ul>
            </li>
        </ul>
        
        <a href="../kubernetes-basics/index.html" class="button" id="tryKubernetes" data-auto-burger-exclude>Try Kubernetes</a>
        <button id="hamburger" onclick="kub.toggleMenu()" data-auto-burger-exclude><div></div></button>
    </div>

    <nav id="mainNav">
        <main data-auto-burger="primary">
        <div class="nav-box">
            <h3><a href="../stateless-application/hello-minikube/index.html">Get Started</a></h3>
            <p>Ready to get your hands dirty? Build a simple Kubernetes cluster that runs "Hello World" for Node.js.</p>
        </div>
        <div class="nav-box">
            <h3><a href="../../home.1">Documentation</a></h3>
            <p>Learn how to use Kubernetes with the use of walkthroughs, samples, and reference documentation. You can even <a href="../../../editdocs/index.html" data-auto-burger-exclude>help contribute to the docs</a>!</p>
        </div>
        <div class="nav-box">
            <h3><a href="../../../community/index.html">Community</a></h3>
            <p>If you need help, you can connect with other Kubernetes users and the Kubernetes authors, attend community events, and watch video presentations from around the web.</p>
        </div>
        <div class="nav-box">
            <h3><a href="../../../blog/index.html">Blog</a></h3>
            <p>Read the latest news for Kubernetes and the containers space in general, and get technical how-tos hot off the presses.</p>
        </div>
        </main>
        <main data-auto-burger="primary">
        <div class="left">
            <h5 class="github-invite">Interested in hacking on the core Kubernetes code base?</h5>
            <a href="https://github.com/kubernetes/kubernetes" class="button" data-auto-burger-exclude>View On Github</a>
        </div>

        <div class="right">
            <h5 class="github-invite">Explore the community</h5>
            <div class="social">
                <a href="https://twitter.com/kubernetesio" class="twitter"><span>Twitter</span></a>
                <a href="https://github.com/kubernetes/kubernetes" class="github"><span>Github</span></a>
                <a href="http://slack.k8s.io/" class="slack"><span>Slack</span></a>
                <a href="http://stackoverflow.com/questions/tagged/kubernetes" class="stack-overflow"><span>Stack Overflow</span></a>
                <a href="https://discuss.kubernetes.io" class="mailing-list"><span>Forum</span></a>
                <a href="https://calendar.google.com/calendar/embed?src=nt2tcnbtbied3l6gi2h29slvc0%40group.calendar.google.com" class="calendar"><span>Events Calendar</span></a>
            </div>
        </div>
        <div class="clear" style="clear: both"></div>
        </main>
    </nav>
</header>

		
		
		<section id="hero" class="light-text no-sub">
			













<h1>Tutorials</h1>
<h5></h5>




<div id="vendorStrip" class="light-text">
	<ul>
		
		
		<li><a href="../../home.1">DOCUMENTATION</a></li>
		
		
		<li><a href="../../setup/index.html">SETUP</a></li>
		
		
		<li><a href="../../concepts/index.html">CONCEPTS</a></li>
		
		
		<li><a href="../../tasks/index.html">TASKS</a></li>
		
		
		<li><a href="../index.html" class="YAH">TUTORIALS</a></li>
		
		
		<li><a href="../../reference.1">REFERENCE</a></li>
		
	</ul>
	<div id="searchBox">
		<input type="text" id="search" placeholder="Search" onkeydown="if (event.keyCode==13) window.location.replace('/docs/search/?q=' + this.value)" autofocus="autofocus">
	</div>
</div>

		</section>
		
		
<section id="deprecationWarning">
  <main>
    <div class="content deprecation-warning">
      <h3>
        Documentation for Kubernetes v1.11 is no longer actively maintained. The version you are currently viewing is a static snapshot.
        For up-to-date documentation, see the <a href="https://kubernetes.io/docs/home/">latest</a> version.
      </h3>
    </div>
  </main>
</section>


		<section id="encyclopedia">
			
<div id="docsToc">
     <div class="pi-accordion">
    	
        
        
        
        
        
         
             
                 
             
         
             
                 
             
         
             
                 
             
         
             
                 
             
         
             
                 
             
         
             
                 
                          
                          
                 
             
         
             
         
             
         
         
        
        <a class="item" data-title="Tutorials" href="../index.html"></a>

	
	
		
		
<a class="item" data-title="Hello Minikube" href="../stateless-application/hello-minikube/index.html"></a>

		
	
		
		
	<div class="item" data-title="Kubernetes Basics">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Overview" href="../kubernetes-basics/index.html"></a>

		
	
		
		
	<div class="item" data-title="Create a Cluster">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Using Minikube to Create a Cluster" href="../kubernetes-basics/cluster-intro/index.html"></a>

		
	
		
		
<a class="item" data-title="Interactive Tutorial - Creating a Cluster" href="../kubernetes-basics/cluster-interactive/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Deploy an App">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Using kubectl to Create a Deployment" href="../kubernetes-basics/deploy-intro/index.html"></a>

		
	
		
		
<a class="item" data-title="Interactive Tutorial - Deploying an App" href="../kubernetes-basics/deploy-interactive/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Explore Your App">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Viewing Pods and Nodes" href="../kubernetes-basics/explore-intro/index.html"></a>

		
	
		
		
<a class="item" data-title="Interactive Tutorial - Exploring Your App" href="../kubernetes-basics/explore-interactive/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Expose Your App Publicly">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Using a Service to Expose Your App" href="../kubernetes-basics/expose-intro/index.html"></a>

		
	
		
		
<a class="item" data-title="Interactive Tutorial - Exposing Your App" href="../kubernetes-basics/expose-interactive/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Scale Your App">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Running Multiple Instances of Your App" href="../kubernetes-basics/scale-intro/index.html"></a>

		
	
		
		
<a class="item" data-title="Interactive Tutorial - Scaling Your App" href="../kubernetes-basics/scale-interactive/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Update Your App">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Performing a Rolling Update" href="../kubernetes-basics/update-intro/index.html"></a>

		
	
		
		
<a class="item" data-title="Interactive Tutorial - Updating Your App" href="../kubernetes-basics/update-interactive/index.html"></a>

		
	

		</div>
	</div>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Online Training Courses">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Overview of Kubernetes Online Training" href="../online-training/overview/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Configuration">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Configuring Redis using a ConfigMap" href="../configuration/configure-redis-using-configmap/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Stateless Applications">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Exposing an External IP Address to Access an Application in a Cluster" href="../stateless-application/expose-external-ip-address/index.html"></a>

		
	
		
		
<a class="item" data-title="Example: Deploying PHP Guestbook application with Redis" href="../stateless-application/guestbook/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Stateful Applications">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="StatefulSet Basics" href="../stateful-application/basic-stateful-set/index.html"></a>

		
	
		
		
<a class="item" data-title="Example: Deploying WordPress and MySQL with Persistent Volumes" href="../stateful-application/mysql-wordpress-persistent-volume/index.html"></a>

		
	
		
		
<a class="item" data-title="Example: Deploying Cassandra with Stateful Sets" href="../stateful-application/cassandra/index.html"></a>

		
	
		
		
<a class="item" data-title="Running ZooKeeper, A Distributed System Coordinator" href="../stateful-application/zookeeper/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Clusters">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="AppArmor" href="../clusters/apparmor/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Services">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Using Source IP" href="../services/source-ip/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
<a class="item" data-title="Kubernetes 101" href="../../user-guide/walkthrough/index.html"></a>

		
	
		
		
<a class="item" data-title="Kubernetes 201" href="../../user-guide/walkthrough/k8s201/index.html"></a>

		
	






     </div> 
    <button class="push-menu-close-button" onclick="kub.toggleToc()"></button>
</div> 

			<div id="docsContent">
				
<p><a href="../../editdocs#docs/tutorials/k8s101.md" id="editPageButton">Edit This Page</a></p>

<h1>Kubernetes 101</h1>





<h2 id="kubectl-cli-and-pods">Kubectl CLI and Pods</h2>

<p>For Kubernetes 101, we will cover kubectl, Pods, Volumes, and multiple containers.</p>

<p><p>You need to have a Kubernetes cluster, and the kubectl command-line tool must
be configured to communicate with your cluster. If you do not already have a
cluster, you can create one by using
<a href="../../getting-started-guides/minikube">Minikube</a>,
or you can use one of these Kubernetes playgrounds:</p>

<ul>
<li><a href="https://www.katacoda.com/courses/kubernetes/playground" target="_blank">Katacoda</a></li>
<li><a href="http://labs.play-with-k8s.com/" target="_blank">Play with Kubernetes</a></li>
</ul>
 
 To check the version, enter <code>kubectl version</code>.
</p>

<p>In order for the kubectl usage examples to work, make sure you have an example directory locally, either from <a href="https://github.com/kubernetes/kubernetes/releases" target="_blank">a release</a> or the latest <code>.yaml</code> files located <a href="https://github.com/kubernetes/website/tree/master/content/en/docs/tutorials" target="_blank">here</a>.</p>

<nav id="TableOfContents">
<ul>
<li>
<ul>
<li><a href="../../user-guide/walkthrough/index.html#kubectl-cli-and-pods">Kubectl CLI and Pods</a></li>
<li><a href="../../user-guide/walkthrough/index.html#kubectl-cli">Kubectl CLI</a></li>
<li><a href="../../user-guide/walkthrough/index.html#pods">Pods</a>
<ul>
<li>
<ul>
<li><a href="../../user-guide/walkthrough/index.html#pod-definition">Pod Definition</a></li>
<li><a href="../../user-guide/walkthrough/index.html#pod-management">Pod Management</a></li>
<li><a href="../../user-guide/walkthrough/index.html#volumes">Volumes</a>
<ul>
<li><a href="../../user-guide/walkthrough/index.html#volume-types">Volume Types</a></li>
</ul></li>
<li><a href="../../user-guide/walkthrough/index.html#multiple-containers">Multiple Containers</a></li>
</ul></li>
</ul></li>
<li><a href="../../user-guide/walkthrough/index.html#what-s-next">What&rsquo;s Next?</a></li>
</ul></li>
</ul>
</nav>

<h2 id="kubectl-cli">Kubectl CLI</h2>

<p>The easiest way to interact with Kubernetes is through the kubectl command-line interface.</p>

<p>For more info about kubectl, including its usage, commands, and parameters, see <a href="../../user-guide/kubectl-overview.1">Overview of kubectl</a>.</p>

<p>For more information about installing and configuring kubectl, see <a href="../../tasks/kubectl/install/index.html">Install and Set Up kubectl</a>.</p>

<h2 id="pods">Pods</h2>

<p>In Kubernetes, a group of one or more containers is called a <em>Pod</em>. Containers in a Pod are deployed together, and are started, stopped, and replicated as a group.</p>

<p>For more information, see <a href="../../user-guide/pods/index.html">Pods</a>.</p>

<h4 id="pod-definition">Pod Definition</h4>

<p>The simplest Pod definition describes the deployment of a single container.  For example, an nginx web server Pod might be defined as:</p>



 













<table class="includecode" id="pod-nginx-yaml">
    <thead>
        <tr>
            <th>
                <a href="https://github.com/kubernetes/website/blob/master/content/en/docs/tutorials/pod-nginx.yaml" download="pod-nginx.yaml">
                    <code>pod-nginx.yaml docs/tutorials</code>
                </a>
                <img src="../../../images/copycode.svg" style="max-height:24px" onclick="copyCode('pod-nginx-yaml')" title="Copy pod-nginx.yaml to clipboard">
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>Pod<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb"></span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>containers:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb">    </span>image:<span style="color:#bbb"> </span>nginx:<span style="color:#666">1.7</span>.<span style="color:#666">9</span><span style="color:#bbb">
</span><span style="color:#bbb">    </span>ports:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>-<span style="color:#bbb"> </span>containerPort:<span style="color:#bbb"> </span><span style="color:#666">80</span><span style="color:#bbb">
</span><span style="color:#bbb"></span></code></pre></div>  </td>
        </tr>
    </tbody>
</table>



<p>A Pod definition is a declaration of a <em>desired state</em>.  Desired state is a very important concept in the Kubernetes model.  Many things present a desired state to the system, and Kubernetes&rsquo; ensures that the current state matches the desired state.  For example, when you create a Pod and declare that the containers in it to be running. If the containers happen not to be running because of a program failure, Kubernetes continues to (re-)create the Pod in order to drive the pod to the desired state. This process continues until you delete the Pod.</p>

<p>For more information, see <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/README.md" target="_blank">Kubernetes Design Documents and Proposals</a>.</p>

<h4 id="pod-management">Pod Management</h4>

<p>Create a Pod containing an nginx server (<a href="../pod-nginx.yaml">pod-nginx.yaml</a>):</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl create -f docs/tutorials/pod-nginx.yaml</code></pre></div>
<p>List all Pods:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get pods</code></pre></div>
<p>On most providers, the Pod IPs are not externally accessible. The easiest way to test that the pod is working is to create a busybox Pod and exec commands on it remotely. For more information, see <a href="../../tasks/debug-application-cluster/get-shell-running-container/index.html">Get a Shell to a Running Container</a>.</p>

<p>If the IP of the Pod is accessible, you can access its http endpoint with wget on port 80:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl run busybox --image<span style="color:#666">=</span>busybox --restart<span style="color:#666">=</span>Never --tty -i --generator<span style="color:#666">=</span>run-pod/v1 --env <span style="color:#b44">&#34;POD_IP=</span><span style="color:#a2f;font-weight:bold">$(</span>kubectl get pod nginx -o go-template<span style="color:#666">=</span><span style="color:#b44">&#39;{{.status.podIP}}&#39;</span><span style="color:#a2f;font-weight:bold">)</span><span style="color:#b44">&#34;</span>
u@busybox$ wget -qO- http://<span style="color:#b8860b">$POD_IP</span> <span style="color:#080;font-style:italic"># Run in the busybox container
</span><span style="color:#080;font-style:italic"></span>u@busybox$ <span style="color:#a2f">exit</span> <span style="color:#080;font-style:italic"># Exit the busybox container
</span><span style="color:#080;font-style:italic"></span>$ kubectl delete pod busybox # Clean up the pod we created with <span style="color:#b44">&#34;kubectl run&#34;</span></code></pre></div>
<p>To delete a Pod named nginx:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl delete pod nginx</code></pre></div>
<h4 id="volumes">Volumes</h4>

<p>That&rsquo;s great for a simple static web server, but what about persistent storage?</p>

<p>The container file system only lives as long as the container does. So if your app&rsquo;s state needs to survive relocation, reboots, and crashes, you&rsquo;ll need to configure some persistent storage.</p>

<p>In this example you can create a Redis Pod with a named volume, and a volume mount that defines the path to mount the Volume.</p>

<ol>
<li>Define a Volume:</li>
</ol>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">volumes:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>redis-persistent-storage<span style="color:#bbb">
</span><span style="color:#bbb">      </span>emptyDir:<span style="color:#bbb"> </span>{}</code></pre></div>
<ol>
<li>Define a Volume mount within a container definition:</li>
</ol>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">volumeMounts:<span style="color:#bbb">
</span><span style="color:#bbb">    </span><span style="color:#080;font-style:italic"># name must match the volume name defined in volumes</span><span style="color:#bbb">
</span><span style="color:#bbb">    </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>redis-persistent-storage<span style="color:#bbb">
</span><span style="color:#bbb">      </span><span style="color:#080;font-style:italic"># mount path within the container</span><span style="color:#bbb">
</span><span style="color:#bbb">      </span>mountPath:<span style="color:#bbb"> </span>/data/redis</code></pre></div>
<p>Here is an example of Redis Pod definition with a persistent storage volume (<a href="../pod-redis.yaml">pod-redis.yaml</a>):</p>



 













<table class="includecode" id="pod-redis-yaml">
    <thead>
        <tr>
            <th>
                <a href="https://github.com/kubernetes/website/blob/master/content/en/docs/tutorials/pod-redis.yaml" download="pod-redis.yaml">
                    <code>pod-redis.yaml docs/tutorials</code>
                </a>
                <img src="../../../images/copycode.svg" style="max-height:24px" onclick="copyCode('pod-redis-yaml')" title="Copy pod-redis.yaml to clipboard">
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>Pod<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>redis<span style="color:#bbb">
</span><span style="color:#bbb"></span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>containers:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>redis<span style="color:#bbb">
</span><span style="color:#bbb">    </span>image:<span style="color:#bbb"> </span>redis<span style="color:#bbb">
</span><span style="color:#bbb">    </span>volumeMounts:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>redis-persistent-storage<span style="color:#bbb">
</span><span style="color:#bbb">      </span>mountPath:<span style="color:#bbb"> </span>/data/redis<span style="color:#bbb">
</span><span style="color:#bbb">  </span>volumes:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>redis-persistent-storage<span style="color:#bbb">
</span><span style="color:#bbb">    </span>emptyDir:<span style="color:#bbb"> </span>{}<span style="color:#bbb">
</span><span style="color:#bbb"></span></code></pre></div>  </td>
        </tr>
    </tbody>
</table>



<p>Where:</p>

<ul>
<li>The <code>volumeMounts</code> <code>name</code> is a reference to a specific  <code>volumes</code> <code>name</code>.</li>
<li>The <code>volumeMounts</code> <code>mountPath</code> is the path to mount the volume within the container.</li>
</ul>

<h5 id="volume-types">Volume Types</h5>

<ul>
<li><strong>EmptyDir</strong>: Creates a new directory that exists as long as the Pod is running on the node, but it can persist across container failures and restarts.</li>
<li><strong>HostPath</strong>: Mounts an existing directory on the node&rsquo;s file system. For example (<code>/var/logs</code>).</li>
</ul>

<p>For more information, see <a href="../../concepts/storage/volumes.1">Volumes</a>.</p>

<h4 id="multiple-containers">Multiple Containers</h4>

<p><em>Note:
The examples below are syntactically correct, but some of the images (e.g. kubernetes/git-monitor) don&rsquo;t exist yet.  We&rsquo;re working on turning these into working examples.</em></p>

<p>However, often you want to have two different containers that work together.  An example of this would be a web server, and a helper job that polls a git repository for new updates:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>Pod<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>www<span style="color:#bbb">
</span><span style="color:#bbb"></span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>containers:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb">    </span>image:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb">    </span>volumeMounts:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>-<span style="color:#bbb"> </span>mountPath:<span style="color:#bbb"> </span>/srv/www<span style="color:#bbb">
</span><span style="color:#bbb">      </span>name:<span style="color:#bbb"> </span>www-data<span style="color:#bbb">
</span><span style="color:#bbb">      </span>readOnly:<span style="color:#bbb"> </span><span style="color:#a2f;font-weight:bold">true</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>git-monitor<span style="color:#bbb">
</span><span style="color:#bbb">    </span>image:<span style="color:#bbb"> </span>kubernetes/git-monitor<span style="color:#bbb">
</span><span style="color:#bbb">    </span>env:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>GIT_REPO<span style="color:#bbb">
</span><span style="color:#bbb">      </span>value:<span style="color:#bbb"> </span>http://github.com/some/repo.git<span style="color:#bbb">
</span><span style="color:#bbb">    </span>volumeMounts:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>-<span style="color:#bbb"> </span>mountPath:<span style="color:#bbb"> </span>/data<span style="color:#bbb">
</span><span style="color:#bbb">      </span>name:<span style="color:#bbb"> </span>www-data<span style="color:#bbb">
</span><span style="color:#bbb">  </span>volumes:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>www-data<span style="color:#bbb">
</span><span style="color:#bbb">    </span>emptyDir:<span style="color:#bbb"> </span>{}</code></pre></div>
<p>Note that we have also added a Volume here.  In this case, the Volume is mounted into both containers.  It is marked <code>readOnly</code> in the web server&rsquo;s case, since it doesn&rsquo;t need to write to the directory.</p>

<p>Finally, we have also introduced an environment variable to the <code>git-monitor</code> container, which allows us to parameterize that container with the particular git repository that we want to track.</p>

<h2 id="what-s-next">What&rsquo;s Next?</h2>

<p>Continue on to <a href="../../user-guide/walkthrough/k8s201/index.html">Kubernetes 201</a> or
for a complete application see the <a href="https://github.com/kubernetes/examples/tree/v1.11.3/guestbook/" target="_blank">guestbook example</a></p>



				<div class="issue-button-container">
					<p><a href="../../user-guide/walkthrough/index.html"><img src="https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/tutorials/k8s101.md?pixel" alt="Analytics" /></a></p>
					
					
					<script type="text/javascript">
					PDRTJS_settings_8345992 = {
					"id" : "8345992",
					"unique_id" : "\/docs\/tutorials\/k8s101\/",
					"title" : "Kubernetes 101",
					"permalink" : "https:\/\/kubernetes.io\/docs\/tutorials\/k8s101\/"
					};
					(function(d,c,j){if(!document.getElementById(j)){var pd=d.createElement(c),s;pd.id=j;pd.src=('https:'==document.location.protocol)?'https://polldaddy.com/js/rating/rating.js':'http://i0.poll.fm/js/rating/rating.js';s=document.getElementsByTagName(c)[0];s.parentNode.insertBefore(pd,s);}}(document,'script','pd-rating-js'));
					</script>
					<a href="../../user-guide/walkthrough/index.html" onclick="window.open('https://github.com/kubernetes/website/issues/new?title=Issue%20with%20' +
					'k8s.io'+window.location.pathname)" class="button issue">Create an Issue</a>
					
					
					
					<a href="../../editdocs#docs/tutorials/k8s101.md" class="button issue">Edit this Page</a>
					
				</div>
			</div>
		</section>
		<footer>
    <main class="light-text">
        <nav>
            
            
            
            <a href="../../home.1">Documentation</a>
            
            <a href="../../../blog/index.html">Blog</a>
            
            <a href="../../../partners/index.html">Partners</a>
            
            <a href="../../../community/index.html">Community</a>
            
            <a href="../../../case-studies/index.html">Case Studies</a>
            
        </nav>
        <div class="social">
            <div>
                <a href="https://twitter.com/kubernetesio" class="twitter"><span>twitter</span></a>
                <a href="https://github.com/kubernetes/kubernetes" class="github"><span>Github</span></a>
                <a href="http://slack.k8s.io/" class="slack"><span>Slack</span></a>
            </div>
            <div>
                <a href="http://stackoverflow.com/questions/tagged/kubernetes" class="stack-overflow"><span>Stack Overflow</span></a>
                <a href="https://discuss.kubernetes.io" class="mailing-list"><span>Forum</span></a>
                <a href="https://calendar.google.com/calendar/embed?src=nt2tcnbtbied3l6gi2h29slvc0%40group.calendar.google.com" class="calendar"><span>Events Calendar</span></a>
            </div>
            <div>
                <a href="../../getting-started-guides/index.html" class="button">Get Kubernetes</a>
                <a href="https://git.k8s.io/community/contributors/guide" class="button">Contribute</a>
            </div>
        </div>
        <div id="miceType" class="center">
            &copy; 2018 The Kubernetes Authors | Documentation Distributed under <a href="https://git.k8s.io/website/LICENSE" class="light-text">CC BY 4.0</a>
        </div>
        <div id="miceType" class="center">
            Copyright &copy; 2018 The Linux Foundation&reg;. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our <a href="https://www.linuxfoundation.org/trademark-usage" class="light-text">Trademark Usage page</a>
        </div>
    </main>
</footer>

		<button class="flyout-button" onclick="kub.toggleToc()"></button>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-36037335-10', 'auto');
ga('send', 'pageview');


(function () {
    window.addEventListener('DOMContentLoaded', init)

        
        function init() {
            window.removeEventListener('DOMContentLoaded', init)
                hideNav()
        }

    function hideNav(toc){
        if (!toc) toc = document.querySelector('#docsToc')
        if (!toc) return
            var container = toc.querySelector('.container')

                
                if (container) {
                    if (container.childElementCount === 0 || toc.querySelectorAll('a.item').length === 1) {
                        toc.style.display = 'none'
                            document.getElementById('docsContent').style.width = '100%'
                    }
                } else {
                    requestAnimationFrame(function () {
                        hideNav(toc)
                    })
                }
    }
})();
</script>



	</body>
</html>